package com.example.lawyer.interfaceservice;

import com.example.lawyer.interfacecallback.ActivityMainDatabindCallback;
import com.example.lawyer.interfacemethod.ActivityMainDatabindInter;

import java.io.IOException;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class ActivityMainDatabindService  implements ActivityMainDatabindInter {


    private  ActivityMainDatabindCallback mainDatabindCallback;
    public ActivityMainDatabindService(ActivityMainDatabindCallback mainDatabindCallback) {
        this.mainDatabindCallback = mainDatabindCallback;
    }



    @Override
    public void GetConverUrl() {

//        请求服务器
//        String s = HttpRequestOk(AppRequestUrlList.APP_START_COVER_URL, null);

        if(mainDatabindCallback!=null)
        {
            mainDatabindCallback.OnCoverDataResult("http://aikebuluo.kakeqd.com/public/cover.jpg");
        }
    }


    /****
     * 数据请求
     * @param url
     * @param body
     * @return
     */
    private String HttpRequestOk(String url,String body)
    {

        String result = null;
        try {
            OkHttpClient client = new OkHttpClient();
            RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), body);
            Request build = new Request.Builder().url(url).post(requestBody).build();
            Response execute = client.newCall(build).execute();
            result = execute.body().string();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

}
